import component from "../../../common/component";
import {Button, Tag} from "antd";
import EditModal from "./edit";
import DelBtn from "@/components/DelBtn"


class equtype extends component {
     //右上角 新建设备类型与删除选中 按钮
    getButtonRow(): null {
        return <>
            <Button className={'button-delete button-default'}
                    onClick={this.handleAdd}
                    type="primary">
                    实验室预约发布
            </Button>
               </>;
    }
    //主体部分页眉
    getColumns(): null {
        return [
            {
                title: '实验名称',
                dataIndex: 'tiliteName',
                key: 'tiliteName',
                width: 150,  
            },
            {
                title: '实验地点',
                dataIndex: 'location',
                key: 'location',
                width: 150,  
            },
            {
                title: '发布时间',
                dataIndex: 'releaseTime',
                key: 'releaseTime',
                width: 150,  
                sorter: (a, b) => {
                    // 将日期转成毫秒
                      const t1 = new Date(a.releaseTime).getTime();
                      const t2 = new Date(b.releaseTime).getTime();
                      return t1- t2
                    },
                    sortDirections: ['descend', 'ascend'],
                    defaultSortOrder: 'descend'
            },
            {
                title: '人数下限',
                dataIndex: 'peopleMin',
                key: 'peopleMin',
                width: 150,  
            },
            {
                title: '人数上限',
                dataIndex: 'peopleMax',
                key: 'peopleMax',
                width: 150,  
            },
            {
                title: '开始时间',
                dataIndex: 'stime',
                key: 'stime',
                width: 150,  
            },
            {
                title: '结束时间',
                dataIndex: 'etime',
                key: 'etime',
                width: 150,  
            },
            {
                title: '状态',
                dataIndex: 'state',
                key: 'state',
                width: 150,  
                render (state) { 
                    let config = {                      
                        '0': <Tag color="success">已发布</Tag>,
                        '1': <Tag color='default'>已拒绝</Tag>,
                        '2': <Tag color="processing">已通过</Tag>,
                    }
                    return config[state];
                }
            },
            {
                title: '是否达到上限',
                dataIndex: 'enable',
                key: 'enable',
                width: 150,  
                render (enable) { 
                    let config = {                      
                        '0': <Tag color="default">未达到</Tag>,
                        '1': <Tag color='success'>已达到</Tag>,
                    }
                    return config[enable];
                }
            },
            {
                title: '已预约人数',
                dataIndex: 'people',
                key: 'people',
                width: 150,  
            },
            {
                title: '可预约用户类型',
                dataIndex: 'type',
                key: 'type',
                width: 150,  
                render (type) { 
                    let config = {                      
                        '0': <Tag color="default">本科生</Tag>,
                        '1': <Tag color='success'>研究生</Tag>,
                    }
                    return config[type];
                }
            },
            {
                title: '操作',
                dataIndex: 'operation',
                fixed: 'right',
                width: 150,  
                render: (_, record) => {
                    return <DelBtn record={record} del={this.delete}/>
                },
            }
        ];
    }

    getEditModal(): null {
        return <EditModal {...this.state.editParam} cancelModal={this.cancelModal}
            reload={this.reload}  baseUir={this.state.baseUri}/>
    }
}

export default equtype;
